package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.user.pojo.param.UserLoginParam;
import com.tarena.lbs.user.pojo.param.UserParam;
import com.tarena.lbs.user.pojo.param.UserTagsParam;
import com.tarena.lbs.user.pojo.vo.LoginVO;
import com.tarena.lbs.user.pojo.vo.UserVO;
import com.tarena.lbs.user.service.LoginService;
import com.tarena.lbs.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 手机小程序用户处理
 */
@Slf4j
@Tag(name = "用户接口")
@RestController
public class UserController {


    @Autowired
    private LoginService loginService;

    @Autowired
    private UserService userService;

    @Operation(summary = "用户登录")
    @PostMapping("/passport/user/login")
    public Result<LoginVO> userLogin(UserLoginParam param)
            throws BusinessException{
        log.debug("用户登录，入参：{}",param);
        LoginVO loginVO = loginService.userLogin(param);
        log.debug("用户登录成功，入参:{},出参:{}",param,loginVO);
        return new Result<>(loginVO);
    }

    @Operation(summary = "用户注册")
    //小程序新增注册
    @PostMapping("/basic/user/info/register")
    public Result<Void> register(@RequestBody UserParam param)
        throws BusinessException{
        log.debug("用户注册，入参：{}",param);
        userService.register(param);
        log.debug("用户注册成功，入参:{}",param);
        return Result.success();
    }

    //解析jwt 拿到id获取登录用户性情
    @Operation(summary = "用户详情")
    @GetMapping("/basic/user/detail")
    public Result<UserVO> detail()throws BusinessException{
        log.debug("查询登录用户详情");
        UserVO detail = userService.detail();
        log.debug("查询登录用户详情成功，出参:{}",detail);
        return new Result<>(detail);
    }

    //用户提交绑定关联所选标签
    @Operation(summary = "用户标签关联")
    @GetMapping("/basic/user/tag")
    public Result<Void> bindUserTags(UserTagsParam param)
            throws BusinessException{
        return null;
    }

}
